<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-05 15:16:04
 * @LastEditTime : 2019-12-27 17:18:23
 * @LastEditors  : Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style type="text/css">
        .row {
            margin-top: 10px
        }

        .row:last-child {
            margin-bottom: 10px;
        }

        .ov {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-size: 14px;
        }

        /* .van-cell__value {
             text-align: right;
         } */

        .label {
            font-weight: 500;
            font-size: 13px;
            color: #969799;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="init-full">
            <van-nav-bar class="head" :title="'应付(' + name + ')'" left-arrow @click-left="onClickLeft">
                <div slot="right" class="head-right">
                    <span @click="showSearch = true;">
                        <img src="../image/search.png" />
                    </span>
                </div>
            </van-nav-bar>
            <div class="body-no-bottom">
                <div class="content">
                    <van-list v-model="listLoading2" :finished="listFinished2" finished-text="没有更多了"
                        @load="listOnLoad(2)">
                        <div class="row" v-for="(row,index) in dataList2" @click="intoRow(row)">
                            <van-cell clickable>
                                <div>
                                    <van-row gutter="20">
                                        <van-col span="14" class="ov">{{row.BillNO || '暂无单据号'}}</van-col>
                                        <van-col span="10">{{row.BDate}}</van-col>
                                    </van-row>
                                </div>
                                <div class="label">
                                    <van-row gutter="20">
                                        <van-col span="14">来源:{{row.BillName}}</van-col>
                                        <van-col span="10"><b style="color: #000;">金额:{{row.DMoney}}</b></van-col>
                                    </van-row>
                                    <van-row gutter="20">
                                        <van-col span="14"><b style="color: #cd1b21;">应付余额:{{row.YMoney}}</b></van-col>
                                    </van-row>
                                </div>
                            </van-cell>
                        </div>
                    </van-list>
                </div>
                <van-loading v-if="showLoading" />
            </div>

            <!-- <div class="bottom">
                <div class="bottom-left-label">
                    <span>合计：</span>
                    <span class="number">￥{{totalMoney}}</span>
                </div>
                <div class="bottom-right-button">
                    <van-button type="primary" block @click="showPay = true;payMoney = '';">支付</van-button>
                </div>
            </div> -->
        </div>

        <van-popup v-model="showSearch" round position="bottom">
            <div>
                <van-cell title="开始时间" :value="searchData.S_SDate" @click="openDate(1)">
                </van-cell>
                <van-cell title="结束时间" :value="searchData.S_EDate" @click="openDate(2)">
                </van-cell>
            </div>
            <div class="btn-padding">
                <van-button type="primary" block style="border-radius: 0;" @click="searchList">查询</van-button>
            </div>
        </van-popup>


        <van-popup v-model="showDate" round position="bottom">
            <van-datetime-picker v-model="currentDate" type="date" @confirm="confirmDate" @cancel="cancelDate"
                cancel-button-text="清空" />
        </van-popup>

        <van-dialog v-model="showPay" close-on-click-overlay @confirm="moneyPay">
            <div style="padding-top:30px;">
                <van-field label="收款金额" v-model="payMoney" type="number" placeholder="请输入支付金额"></van-field>
            </div>
        </van-dialog>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {
        //$('.init-full').show();


        api.addEventListener({
            name: 'reloadForm'
        }, function (ret, err) {
            var obj = {
                S_YWType: 1,
                S_SDate: '1900-01-01',
                S_EDate: '1900-01-01'
            }
            FLD.ajax('APWL_YFZKLB', obj, function (res) {
                totalMoney = res.ds[0].ARMoney;
                vm.totalMoney = totalMoney;
            })
        })

        var type = api.pageParam.type;
        var userInfo = FLD.getUserInfo();
        var dateIndex = 0;
        vm = new Vue({
            el: '#app',
            data: {
                showLoading: false,
                ifConfirm: false,
                showSearch: false,
                showPay: false,
                type: type,
                totalMoney: 0,
                tabActive: type - 2,
                name:api.pageParam.name,
                listLoading1: false,
                listFinished1: true,
                listLoading2: false,
                listFinished2: true,
                listLoading3: false,
                listFinished3: true,
                dataList1: [],
                dataList2: [],
                dataList3: [],
                pageIndex1: 1,
                pageSize1: 20,
                pageIndex2: 1,
                pageSize2: 20,
                pageIndex3: 1,
                pageSize3: 20,
                currentDate: new Date(),
                showDate: false,
                searchData: {
                    S_SDate: '',
                    S_EDate: ''
                },
                payMoney: ''

            },
            created: function () {

                this.getTotal();

                this.getList();
            },
            methods: {
                getTotal() {
                    var that = this;
                    var obj = {
                        S_YWType: 1,
                        S_SDate: '1900-01-01',
                        S_EDate: '1900-01-01',
                        S_BranchID:api.pageParam.S_BranchID,
                        S_ClientID:api.pageParam.S_ClientID
                    }
                    FLD.ajax('APWL_YFZKLB', obj, function (res) {
                        totalMoney = res.ds[0].ARMoney;
                        that.totalMoney = totalMoney;
                    })
                },
                getList() {
                    var that = this;
                    that.showLoading = true;
                    // var obj1 = {
                    //     S_YWType: 1,
                    //     S_Pageindex: that.pageIndex1,
                    //     S_PageSize: that.pageSize1,
                    //     S_SDate: that.searchData.S_SDate || '1900-01-01',
                    //     S_EDate: that.searchData.S_EDate || '2999-01-01'
                    // }
                    // FLD.ajax('APWL_YFZKLB', obj1, function (res) {
                    //     that.showLoading = false;
                    //     that.listFinished1 = false;
                    //     that.dataList1 = res.ds;
                    // })
                    var obj2 = {
                        S_YWType: 2,
                        S_Pageindex: that.pageIndex2,
                        S_PageSize: that.pageSize2,
                        S_SDate: that.searchData.S_SDate || '1900-01-01',
                        S_EDate: that.searchData.S_EDate || '2999-01-01',
                        S_BranchID:api.pageParam.S_BranchID,
                        S_ClientID:api.pageParam.S_ClientID
                    }
                    FLD.ajax('APWL_YFZKLB', obj2, function (res) {
                        that.showLoading = false;
                        that.listFinished2 = false;
                        that.dataList2 = res.ds;
                    })
                    // var obj3 = {
                    //     S_YWType: 3,
                    //     S_Pageindex: that.pageIndex3,
                    //     S_PageSize: that.pageSize3,
                    //     S_SDate: that.searchData.S_SDate || '1900-01-01',
                    //     S_EDate: that.searchData.S_EDate || '2999-01-01'
                    // }
                    // FLD.ajax('APWL_YFZKLB', obj3, function (res) {

                    //     that.showLoading = false;
                    //     that.listFinished3 = false;
                    //     that.dataList3 = res.ds;
                    // })
                },
                listOnLoad(index) {
                    var that = this;
                    that['pageIndex' + index]++;
                    var obj = {
                        S_YWType: index,
                        S_Pageindex: that['pageIndex' + index],
                        S_PageSize: that['pageSize' + index],
                        S_SDate: that.searchData.S_SDate || '1900-01-01',
                        S_EDate: that.searchData.S_EDate || '2999-01-01'
                    }
                    FLD.ajax('APWL_YFZKLB', obj, function (res) {
                        that['listLoading' + index] = false;
                        if (res.ds.length == 0) {
                            that['listFinished' + index] = true;
                        }
                        that['dataList' + index] = that['dataList' + index].concat(res.ds);
                    })
                },
                searchList() {
                    var that = this;
                    that.showSearch = false;

                    that.pageIndex1 = 1;
                    that.pageIndex2 = 1;
                    that.pageIndex3 = 1;

                    this.getList();
                },
                openDate(index) {
                    dateIndex = index;
                    this.currentDate = new Date()
                    this.showDate = true;
                },
                confirmDate(value) {
                    if (dateIndex == 1) {
                        this.searchData.S_SDate = FLD.getFormatDate(value).split(' ')[0]
                    } else {
                        this.searchData.S_EDate = FLD.getFormatDate(value).split(' ')[0]
                    }
                    this.showDate = false;
                },
                cancelDate(value) {
                    if (dateIndex == 1) {
                        this.searchData.S_SDate = '';
                    } else {
                        this.searchData.S_EDate = '';
                    }
                    this.showDate = false;
                },
                moneyPay() {
                    var that = this;
                    api.openWin({
                        name: 'pay',
                        url: 'common/pay.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            payData: {
                                S_DMoney: that.payMoney,
                                S_UserType: 2,
                                S_PayType: '0'
                            },
                            payType: 2
                        }
                    })
                },
                intoRow(row) {
                    if (row.BillName == '销售出库单') {
                        api.openWin({
                            name: 'selling1',
                            url: 'selling1.html',
                            reload: true,
                            slidBackEnabled: false,
                            pageParam: {
                                historyData: row
                            }
                        })

                    }

                },
                onClickLeft() {
                    api.closeWin();
                }
            }
        })
    };
</script>

</html>